const app = getApp();
const pageOptions = {
  // 页面数据
  data: {
    addStaff: false,
    staffPhone: "",
    staffNmae: "",
  },
  // 页面载入时
  onLoad(e) {
    this.init(e);
    this.getData();
  },
  // 页面初始化
  init(e) {},
  // 页面准备好时
  onReady() {},
  // 页面显示时
  onShow() {},
  // 页面隐藏时
  onHide() {},
  // 页面卸载时
  onUnload() {},
  // 下拉页面时
  onPullDownRefresh() {},
  // 到达页面底部时
  onReachBottom() {},
  // 页面滚动时
  onPageScroll() {},
  // 分享时，注：onShareAppMessage不能为async异步函数，会导致不能及时取得返回值，使得分享设置无效
  onShareAppMessage() {
    /* const title = ''
    const path = ''
    const imageUrl = ``

    return {
      title,
      path,
      imageUrl,
    } */
  },
  async onClickRight() {
    console.log(this.data.staffPhone)
    let {
      data
    } = await app._getNetWork({
      url: app.getNetAddresss("plugin.project-party.frontend.controllers.index.addStaff"),
      data: {
        tel: this.data.staffPhone,
        name: this.data.staffNmae
      }
    })
    if (data.result) {
      app.tips(data.msg);
      this.getData();
    } else {
      app.tips(data.msg)
    }
    this.setData({
      addStaff: false,
    });
    console.log(data)
  },
  async delMthod(e) {
    let tel = e.currentTarget.dataset.tel;
    let {
      data
    } = await app._getNetWork({
      url: app.getNetAddresss("plugin.project-party.frontend.controllers.index.delStaff"),
      data: {
        tel: tel,
      }
    })
    if (data.result) {
      app.tips(data.msg);
      this.onClickLeft();
      this.getData();
    } else {
      app.tips(data.msg)
    }
  },
  async getData() {
    let {
      data
    } = await app._getNetWork({
      url: app.getNetAddresss("plugin.project-party.frontend.controllers.index.staffList")
    })
    if (data.result) {
      this.setData({
        list: data.data.data,
        staff_num: data.data.staff_num
      })
    } else {
      app.tips(data.msg)
    }
  },
  addStaffOpen() {
    this.setData({
      addStaff: true,
      staffNmae: "",
      staffPhone: ""
    });
  },
  inpName(e) {
    this.setData({
      staffNmae: e.detail.value
    })
  },
  inpTel(e) {
    this.setData({
      staffPhone: e.detail.value
    })
  },

  onClickLeft() {
    this.setData({
      addStaff: false,
      staffPhone: "",
      staffNmae: ""
    })
  }
};

Page(pageOptions);